package com.example.offer.no0011.impl;

import com.example.offer.no0011.Solution;

/**
 * @author yumuhui <yumuhui@kuaishou.com>
 * Created on 2021-05-13
 */
public class SolutionImpl implements Solution {

    @Override
    public int minArray(int[] numbers) {

        int left = 0;
        int right = numbers.length - 1;

        while (left < right) {
            int middle = (right + left) / 2;
            if (numbers[middle] < numbers[right]) {
                right = middle;
            } else if (numbers[middle] > numbers[right]) {
                left = middle + 1;
            } else {
                right--;
            }
        }

        return numbers[left];
    }
}
